#include "OLSpinnerSurface.h"
#include "OLApplication.h"

#include <QMovie>
#include <QLabel>
#include <QResizeEvent>

#include <QVBoxLayout>

OLSpinnerSurface::OLSpinnerSurface(const QString caption, QWidget *parent) :
    OLModalBackground(parent)
{
    QMovie *movie = new QMovie(":/gfx/spinner.gif", QByteArray(), this);
    movie->setCacheMode(QMovie::CacheAll);
    movie->setScaledSize(QSize(40, 40));

    QLabel* label = new QLabel(this);
    label->setMovie(movie);

    m_spinnerCaption = new QLabel(this);
    m_spinnerCaption->setText(caption);

    QVBoxLayout* layout = new QVBoxLayout();
    layout->addStretch();
    layout->addWidget(label,0,Qt::AlignCenter);
    layout->addWidget(m_spinnerCaption,0,Qt::AlignCenter);
    layout->addStretch();
    setLayout(layout);

    movie->start();
}

void OLSpinnerSurface::setCaption(const QString& caption)
{
    m_spinnerCaption->setText(caption);
}

void OLSpinnerSurface::handleAppResize()
{
    resize(parentWidget()->size());
}

void OLSpinnerSurface::handleViewResize(const QSize& size)
{
    setGeometry(OLApp->viewParent()->geometry());
}

